﻿using System.Linq;
using Inovout.Land;
using Inovout.Gis.Geometry;
using System.Collections.Generic;
using Inovout.Land.Domain;
using System;

namespace Inovout.Gis.Land
{
    public class TuBanLineLayer : TuBanGeometryLayer
    {
        #region Constructor

        internal TuBanLineLayer(IGeometryLayerInfo layerInfo) :
            base(layerInfo)
        {
   
        }

        #endregion
    
        public IEnumerable<TuBanLine> Lines
        {
            get { return base.Geometries.Cast<TuBanLine>(); }
        }

        private List<TuBan> tuBans;
        public List<TuBan> TuBans
        {
            get 
            {
                if (tuBans == null)
                {
                    tuBans = GetTuBans();
                }
                return tuBans;
            }
        }


        private List<TuBan> GetTuBans()
        {
            Dictionary<DiLei,TuBan> dlTuBans = new Dictionary<DiLei,TuBan>();
            foreach (var line in Lines)
            {
                TuBan tuBan;
                if (!dlTuBans.TryGetValue(line.TuBan.DiLei, out tuBan))
                {
                    tuBan = new TuBan { DiLei = line.TuBan.DiLei, Area = line.TuBan.Area };
                    dlTuBans.Add(tuBan.DiLei, tuBan);
                }
                else
                {
                    dlTuBans[tuBan.DiLei].Area = +line.TuBan.Area;
                }

            }
            return dlTuBans.Values.ToList();
        }
        //internal List<FLMJX> GetDLMJXs()
        //{
        //    double mj = 0;
        //    foreach (var line in Lines)
        //    {
        //        string dl = line.DLCode;
        //        mj = +line.Area;
        //    }
        //    return null;
        //}

        //internal void Intersect(IGeometryInfo geometry, out double mj)
        //{
        //    mj = 0;
        //    double intersectArea = 0;
        //    foreach (var line in Lines)
        //    {
        //        line.Intersect(geometry, out mj);
        //        intersectArea += mj;
        //    }
        //    mj = intersectArea;
        //}
    }
}
